package com.song.workpool.control;

import java.util.List;
import java.util.Vector;

import com.song.email.bean.EmailInfo;
import com.song.email.bean.Work;
import com.song.email.core.WorkCenter;
import com.song.email.util.common.Config;
import com.song.workpool.WorkThreadPool;
import com.song.workpool.taskimpl.SendEmailTask;

public class SendEmailTaskControl extends AbstractTaskControl<EmailInfo> {
//	private Log log = LogFactory.getLog(SendEmailTaskControl.class);
	private static WorkThreadPool pool = null;
	private static SendEmailTaskControl instance = null;

	private SendEmailTaskControl() {
		pool = new WorkThreadPool("SendEmailWorkThread", Config.sendThreadNum);
		this.init(Config.sendFrequency);
	}

	public synchronized static SendEmailTaskControl getInstance() {
		if (instance == null && Config.isStart == 1) {
			instance = new SendEmailTaskControl();
		}
		return instance;
	}
	
	public void SendEmailAsy() {
		Vector<Work> workList = WorkCenter.getInstance().getWorkList();
		for(Work work : workList){
			pool.addTask(new SendEmailTask(work));
		}
	}
	
	public void SendEmailAsy(List<Work> workLs) {
		for(Work work : workLs){
			pool.addTask(new SendEmailTask(work));
		}
	}

	public void SendEmailAsy(Work work) {
		pool.addTask(new SendEmailTask(work));
	}
	
	@Override
	protected void executeTask() {
//		ArrayList<EmailInfo> ls = new ArrayList<EmailInfo>();
//		for (int i = 0; i < this.objDatas.size(); i++) {
//			EmailInfo data = this.objDatas.get(i);
//			ls.add(data);
//		}
//		Task task = new SendEmailTask(ls);
//		try {
//			task.taskPerform();
//		} catch (Exception e) {
//			log.error("发送邮件时出错...",e);
//		}
	}
	
}
